<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <!-- <script src="./test.js"></script> -->

    <script>
        function getTwoOddNumber(arr) {
            let eor = 0,
                eor2 = 0;
            for (let i of arr) {
                eor ^= i;
            }
            // console.log(eor, 7 ^ 9);
            // eor = a ^ b; 两个奇数
            let rightOne = eor & (~eor + 1);
            for (let i of arr) {
                // 偶数项也有与rightOne异或等于1的时候，但是都是偶次。最终变成 0 
                // 只有奇数才会保留。只会保留 a 或者 b 其中一个。
                if ((rightOne & i) == 1) {
                    eor2 ^= i;
                }
            }
            return [eor2, eor ^ eor2];
        }

        console.log(getTwoOddNumber([2, 4]));



        let a = 1;
        let b = 2;
        a = a ^ b;
        b = a ^ b;
        a = a ^ b;
        console.log(a,b);
    </script>


</body>

</html>